package com.zhuiyun.project.api.sysexamine.service.Impl;

import com.zhuiyun.project.api.friend.model.FriendModel;
import com.zhuiyun.project.api.sysexamine.entity.AppPhysician;
import com.zhuiyun.project.api.sysexamine.mapper.AppPhysicianMapper;
import com.zhuiyun.project.api.sysexamine.service.AppPhysicianService;
import com.zhuiyun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AppPhysicianServiceImpl implements AppPhysicianService {

    @Autowired
    AppPhysicianMapper appPhysicianMapper;
    /* *
     * @Author: hui
     * @Descriprion: 进行分页查询的page，size处理
     * @Date: 2023/6/26 14:52
     * @return java.util.List<com.zhuiyun.project.api.sysexamine.entity.AppPhysician>
     * @param page
     * @param size
     * @param doctorName
     */
    @Override
    public PageResult findAll(PageRequest pageRequest, String doctorName) {
        MybatisPageHelper.startPage(pageRequest);
        List<AppPhysician> appPhysicians = appPhysicianMapper.findAll(doctorName);
        return MybatisPageHelper.getPageResult(appPhysicians);
    }

    @Override
    public int update(Integer id) {
        List<FriendModel> friendModels = appPhysicianMapper.selectDoctorAll(id);
        for (int i=0;i<friendModels.size();i++){
            FriendModel friendModel = friendModels.get(i);
            Integer id1 = friendModel.getId();
            appPhysicianMapper.updateDoctor(id1);
        }
        return appPhysicianMapper.update(id);
    }


    @Override
    public int reject(Integer id) {
        return appPhysicianMapper.reject(id);
    }

    @Override
    public List<AppPhysician> fullPhysician(Integer page, Integer size, String doctorName) {
        page = (page-1)* size;
        return appPhysicianMapper.fullPhysician(page,size,doctorName);
    }
}
